package com.itita.ww2.handler.requesthandler.alliance.manager;

import java.sql.SQLException;

import com.itita.ww2.core.MessageHandler;
import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.game.alliance.AllianceService;
import com.itita.ww2.game.user.UserService;
import com.itita.ww2.model.user.UserProfile;
import com.itita.ww2.utils.handler.IRequestOper;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;

public class AllianceCreate implements IRequestOper {

	@Override
	public boolean execute(String requestCMD, User user, ISFSObject params) throws WW2Exception, SQLException {
		UserProfile userProfile = UserService.getInstance().getUserProfile(user);
		String name = params.getUtfString("name"); // 联盟名称
		String declar = params.getUtfString("declar"); // 联盟宣言
		int joinLimit = params.getInt("joinLimit"); // 加入限制
		// String country = params.getUtfString("country"); // 国家
		
		ISFSObject data = AllianceService.createAlliance(userProfile, name, declar, joinLimit);

		ISFSObject backObj = SFSObject.newInstance();
		backObj.putSFSObject("data", data);
		MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, null, true);
		return true;
	}

}
